package com.liu.email;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

public class MySimpleEmail {
	public static void main(String[] args) {
		MailInfo info = new MailInfo();
		sendSimpleEmail(info);
	}

	public static void sendSimpleEmail(MailInfo info) {
		SimpleEmail email = new SimpleEmail();
		email.setHostName(info.getServerHost());
		email.setSmtpPort(Integer.parseInt(info.getServerPort()));
		email.setTLS(info.isNeedSsl());
		if (info.isNeedAuth()) {
			email.setAuthentication(info.getFrom(), info.getPassword()); // 用户名和密码
		}
		try {
			email.setFrom(info.getFrom()); // 发送者
			email.addTo(""); // 接收方
			email.addCc("");// 抄送方
			email.addBcc("");// 密送方
			email.setCharset("GB2312"); // 邮件内容的编码方式
			email.setSubject(""); // 标题
			email.setMsg(""); // 内容
			email.send();
		} catch (EmailException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
